package com.zline.foodraise.adapter;

import android.content.Context;
import android.view.ViewGroup;
import android.widget.RelativeLayout;

import com.photoselector.model.PhotoModel;
import com.photoselector.util.CommonUtils;
import com.zline.foodraise.view.RemovedPhotoItem;
import com.zline.foodraise.view.RemovedPhotoItem_;

import org.androidannotations.annotations.EBean;
import org.androidannotations.annotations.RootContext;

/**
 * Created by heshantao on 15/8/24.
 * 带删除的图片列表适配器
 */
@EBean
public class RemovedPhotoAdapter extends RecyclerViewBaseAdapter<PhotoModel,RemovedPhotoItem> {
    private static final String LOG_TAG=RemovedPhotoAdapter.class.getSimpleName();
    @RootContext
    Context cxt;
    private int itemWidth;
    private int horizentalNum = 4;
    private RelativeLayout.LayoutParams itemLayoutParams;
    @Override
    protected RemovedPhotoItem onCreateItemView(ViewGroup parent, int viewType) {
        RemovedPhotoItem photoItem= RemovedPhotoItem_.build(cxt);
        setItemWidth();
        photoItem.setLayoutParams(itemLayoutParams);
        return photoItem;
    }

    /**
     * 设置每一个Item的宽高
     */
    public void setItemWidth() {
        int screenWidth= CommonUtils.getDeviceWidth(cxt);
        int horizentalSpace = cxt.getResources().getDimensionPixelSize(com.photoselector.R.dimen.sticky_item_horizontalSpacing);
        this.itemWidth = (screenWidth - (horizentalSpace * (horizentalNum - 1))) / horizentalNum;
        this.itemLayoutParams = new RelativeLayout.LayoutParams(itemWidth, itemWidth);
    }

    @Override
    public void onBindViewHolder(ViewWrapper<RemovedPhotoItem> holder, int position) {
        RemovedPhotoItem item=holder.getView();
        PhotoModel photoModel=arrys.get(position);
        item.bind(photoModel,position);
        item.setRecycleItemClickListener(itemClicked);
    }
}
